/**
 * Created by yoyoyk on 2017/3/5.
 *
 * 调用Select下拉菜单时传入参数为数组，格式如下：
 * var _select=[
 {text:"000",value:"aaa"},
 {text:"111",value:"bbb"},
 {text:"222",value:"ccc"},
 {text:"333",value:"ddd"},
 {text:"444",value:"eee"}
 ];
 页面显示为 000
            111
            222
            333
            444
 */
import React , {Component}from 'react';
import Styles from '../util/Styles.js';
export default class Select extends React.Component {
    constructor(props){
        super(props)
        this.state={
            value:'',
            defaultValue:''
        }
        this.Style={}
    }
    changeColor(){}
    addArr(){
        let arr = this.props.oArr;
        return arr.map((item,index)=>{
            if(index===0){
                return (
                    <option value={item.value} key={index+"_"} >{item.text}</option>
                )
            }else{
                return(
                    <option value={item.value} key={index+"_"}>{item.text}</option>
                )
            }


        })
    }
    componentWillMount() {
        this.setState({
            defaultValue:this.props.defaultValue
        });
        this.Style.select={
            width : this.props.style.width || 130,
            height : this.props.style.height || 30,
            borderColor:this.props.style.borderColor || '',
            borderWidth: 1 || this.props.style.width,
            borderRadius: 0 || this.props.style.borderRadius,
            marginLeft:this.props.style.marginLeft || 0,
            marginTop:this.props.style.marginTop || 0,
            outline:"none"
        }
    }
    fetchValue(){
        if(this.props.onselectchose){
            this.props.onselectchose(this.refs.select.value)
        }
        this.setState({
            value:this.refs.select.value
        })
    }

    setdefaultvalue(){
        this.setState({
            value:this.props.defaultValue
        });
    }

    render() {
        return (
                <select className={this.props.className} style={this.Style.select} onChange={this.fetchValue.bind(this)} ref={'select'} defaultValue={this.state.defaultValue}>
                    {
                        this.addArr()
                    }
                </select>
        );
    }
}
